package com.atstudy.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/30 10:55
 * @copyright: 博为峰
 */
public class ClientDemo2 {
    public static void main(String[] args) throws IOException {
        //------------------连接-----------------------------------
        //创建客户端对象
        Socket socket = new Socket("127.0.0.1", 8000);

        //------------------写-数据到服务器端-----------------------------------
        //字节输出流（写）
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("ClientDemo2".getBytes());

        //------------------读-服务器端发来的数据-----------------------------------
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len = inputStream.read(bytes);
        String str = new String(bytes, 0, len);
        System.out.println(str);

        socket.close();
    }
}
